﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.model.gametime;

namespace l1cs.server.serverpackets
{
    public class S_OwnCharStatus : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_OwnCharStatus ).FullName );

        private byte[] _byte = null;

        public S_OwnCharStatus( L1PcInstance pc )
        {
            int time = (int)L1GameTimeClock.getInstance().currentTime().getSeconds();
            time = time - ( time % 300 );
            // _log.warning((new
            // StringBuilder()).append("送信時間:").append(i).toString());
            writeC( Opcodes.S_OPCODE_OWNCHARSTATUS );
            writeD( pc.getId() );

            if ( pc.getLevel() < 1 )
            {
                writeC( 1 );
            }
            else if ( pc.getLevel() > 127 )
            {
                writeC( 127 );
            }
            else
            {
                writeC( pc.getLevel() );
            }
            writeD( pc.getExp() );

            writeC( pc.getStr() );
            writeC( pc.getInt() );
            writeC( pc.getWis() );
            writeC( pc.getDex() );
            writeC( pc.getCon() );
            writeC( pc.getCha() );
            writeH( pc.getCurrentHp() );
            writeH( pc.getMaxHp() );
            writeH( pc.getCurrentMp() );
            writeH( pc.getMaxMp() );
            writeC( pc.getAc() );
            writeD( time );
            writeC( pc.get_food() );
            writeC( pc.getInventory().getWeight240() );
            writeH( pc.getLawful() );
            writeC( pc.getFire() );
            writeC( pc.getWater() );
            writeC( pc.getWind() );
            writeC( pc.getEarth() );
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = _bao.ToArray();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_OwnCharStatus";
        }
    }
}
